/*
 * Copyright 2010 Mark Eschbach.
 *
 * $HeadURL$
 * $Id$
 */
package com.meschbach.cise.dom;

import java.util.Iterator;
import java.util.NoSuchElementException;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

/**
 * @author "Mark Eschbach" &lt;meschbach@gmail.com&gt;
 */
public class NodeIterator<N extends Node> implements Iterator<N> {

    NodeList nodes;
    int index;

    public NodeIterator(NodeList nodes) {
        this.nodes = nodes;
        index = 0;
    }

    public boolean hasNext() {
        return nodes.getLength() > index;
    }

    public N next() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        Node n = nodes.item(index);
        index++;
        return (N) n;
    }

    public N getCurrent() {
        return (N) nodes.item(index - 1);
    }

    public void remove() {
        throw new UnsupportedOperationException("Not enough information available (Use RemovableElementIterator).");
    }
}
